// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.reports.editor.design.utils;

import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;

/**
 * Manages color resource.
 * 
 * /** Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-1-26 qiang.zhang $
 * 
 */
public final class ColorManager {

    /**
     * This map stores color name - Color pairs, used to quickly lookup a Color of a predefined color.
     * 
     * @param c color value
     */
    public static Color getColor(int c) {
        RGB rgb = DEUtil.getRGBValue(c);
        return getColor(rgb);
    }

    /**
     * This map stores color name - Color pairs, used to quickly lookup a Color of a predefined color.
     * 
     * @param red red value of RGB
     * @param green green value of RGB
     * @param blue blue value of RGB
     */
    public static Color getColor(int red, int green, int blue) {
        return getColor(new RGB(red, green, blue));
    }

    /**
     * This map stores color name - Color pairs, used to quickly lookup a Color of a predefined color.
     * 
     * @param rgb RGB value of color
     */
    public static Color getColor(RGB rgb) {
        if (rgb == null) {
            return null;
        }

        String key = rgb.toString();
        Color color = JFaceResources.getColorRegistry().get(key);
        if (color == null) {
            JFaceResources.getColorRegistry().put(key, rgb);
            color = JFaceResources.getColorRegistry().get(key);
        }
        return color;
    }
}